using System.Collections;
using System.Collections.Generic;
using System.Linq;
using ArticleManagementSystem.Api.Db;
using ArticleManagementSystem.Api.Entity;
using ArticleManagementSystem.Api.Params;
using ArticleManagementSystem.Api.Repostisory;
using Microsoft.EntityFrameworkCore;

namespace ArticleManagementSystem.Api.Utils
{
    public class ArticleSelectHelper
    {

        public static dynamic GetArticleMsg(ArrayList articleIds, DataBase context)
        {
            ArrayList list = new ArrayList();
            var table = context.article.ToList();
            var table2 = context.imgs.ToList();
            foreach (var item in articleIds)
            {
                dynamic res = null;
                var msg = table.Where(x => x.Id.Equals(item)).FirstOrDefault();
                
                if (msg != null)
                {
                    msg.Content =  HtmlOrUbb.UBBToHtml(msg.Content);
                    var msg2 = table2.Where(x => x.Id == msg.ImgId).FirstOrDefault();
                    res = new
                    {
                        Article = msg,
                        ImgPath = msg2.ImgsPath
                    };
                    list.Add(res);
                }

            }
            
            return list;
        }
    }
}